/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.m3958.firstgwt.server.model;

import java.util.Date;

import javax.persistence.AttributeOverride;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;

import com.m3958.firstgwt.server.types.IHasSiteId;
import com.m3958.firstgwt.server.types.JsonExcludeFields;
import com.m3958.firstgwt.server.utils.JsonlibDateValueProssor;



@Entity
@Table(name = "DATA_TEMPLATE")
@AttributeOverride(name="id",column=@Column(nullable = false,name="DATA_TEMPLATE_ID"))
@NamedQueries({})
public class DataTemplate extends BaseModel<DataTemplate> implements IHasSiteId{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -8812597083444251003L;
	
	public static class NamedQueries{
	}
	
	private String name;
	
	
	@Lob
	@Column(length=16777210)
	@Basic(fetch=FetchType.LAZY)
	private String tpl;
	
	@Temporal(TemporalType.TIMESTAMP)
	private Date updatedAt;
	
	private int siteId;
	


	@Override
	public JSONObject toJson(){
		JsonConfig jc = new JsonConfig();
		jc.registerJsonValueProcessor(Date.class, injector.getInstance(JsonlibDateValueProssor.class));
		jc.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
		jc.setExcludes(JsonExcludeFields.DATA_TEMPLATE_EXCLUDES);
		return JSONObject.fromObject(this, jc);
	}
	
	@Override
	public JSONObject toJson(String jsonv){
			return toJson();
	}


	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}


	
	@Override
	public int getSiteId() {
		return siteId;
	}

	@Override
	public void setSiteId(int siteId) {
		this.siteId = siteId;
	}

	@Override
	public String[] getJsonExcludes() {
		return null;
	}

	public Date getUpdatedAt() {
		return updatedAt;
	}

	public void setUpdatedAt(Date updatedAt) {
		this.updatedAt = updatedAt;
	}

	public String getTpl() {
		return tpl;
	}

	public void setTpl(String tpl) {
		this.tpl = tpl;
	}

}
